package com.cqie.uaa.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cqie.entity.User;
import com.cqie.uaa.mapper.UserMapper;
import com.cqie.uaa.service.UserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 小飞
 * @since 2024-04-16
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;
    /**
     * 登录
     * @param username
     * @param password
     * @return
     */
    @Override
    public boolean doLogin(String username, String password) {
        User user = userMapper.selectOne(new LambdaQueryWrapper<User>().eq(User::getUsername, username));
        if (user == null || !Objects.equals(user.getPassword(), password)){
            return false;
        }
        StpUtil.login(user.getId());
        return true;
    }
}
